package com.miniprogram.common.utils;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public abstract class RandomUtil {

    private static final Random RANDOM = new Random();
    private static final DateTimeFormatter OFFSET_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");

    public static String RandomCode(int length) {
        StringBuilder stringBuilder = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            stringBuilder.append(RANDOM.nextInt(10));
        }
        return stringBuilder.toString();
    }

    public static String GenerateDateTimeID(String prefix) {
        return prefix + GenerateDateTimeID();
    }

    public static String GenerateDateTimeID() {
        return OFFSET_DATE_TIME_FORMATTER.format(OffsetDateTime.now());
    }

}
